package com.drawner;

import java.util.ArrayList;

import com.witejavi.eneagrama.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DrawnerAdapter extends BaseAdapter {
	private Activity activity;
	ArrayList<DrawnerItem> array;

	public DrawnerAdapter(Activity activity, ArrayList<DrawnerItem> array) {
		super();
		this.activity = activity;
		this.array = array;
	}

	@Override
	public Object getItem(int position) {
		return array.get(position);
	}

	public int getCount() {
		return array.size();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public static class Fila {
		TextView titulo;
		ImageView icono;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		Fila view;
		LayoutInflater inflator = activity.getLayoutInflater();
		if (convertView == null) {
			view = new Fila();
			DrawnerItem itm = array.get(position);
			convertView = inflator.inflate(R.layout.item_drawner, null);

			view.titulo = (TextView) convertView.findViewById(R.id.item_titulo);
			view.titulo.setText(itm.getTitulo());

			view.icono = (ImageView) convertView.findViewById(R.id.item_icon);
			view.icono.setImageResource(itm.getIcono());
			
			convertView.setTag(view);
		} else {
			view = (Fila) convertView.getTag();
		}
		return convertView;
	}
}